package com.longrise.co.ui.home.model;

import com.google.gson.reflect.TypeToken;
import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.co.api.ApiConstants;
import com.longrise.co.api.ApiService;
import com.longrise.co.ui.carlife.model.NewsBean;
import com.longrise.co.ui.home.contract.HomeContract;
import com.ly.common.basebean.BaseResponse;
import com.ly.common.baserx.RxResponseFuncForCar;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by luoyang on 2017-6-23.
 */

public class HomeModel implements HomeContract.Model {

    @Override
    public Observable<CarCompany> carCompanyRequest(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<CarCompany>>(){}.getType(), bean, ApiConstants.APPGETCOMPANYLIST)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<CarCompany>());
    }

    @Override
    public Observable<BindCarInfo> bindCarListRequest(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<BindCarInfo>>(){}.getType(), bean, ApiConstants.APPSEARCHCARS)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<BindCarInfo>());
    }

    @Override
    public Observable<CompanyDetail> companyDetailRequest(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<CompanyDetail>>(){}.getType(), bean, ApiConstants.APPGETCOMPANYINFO)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<CompanyDetail>());
    }

    @Override
    public Observable<NewsBean> getHomeNewsRequest(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<NewsBean>>(){}.getType(), bean, ApiConstants.APPSEARCHNOTICESLIST)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<NewsBean>());

    }

    @Override
    public Observable<CarCompany> nearByCompanyRequest(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<CarCompany>>(){}.getType(), bean, ApiConstants.APPGETCOMPANYLISTRANGE)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<CarCompany>());
    }

    @Override
    public Observable<AreaIdBean> cityAreaIdRequest(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<AreaIdBean>>(){}.getType(), bean, ApiConstants.LCIPGETCITYAREAID)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<AreaIdBean>());
    }
}
